package com.hanamaki.unit.testng.parameter;


import com.hanamaki.unit.junit.util.FileUtil;
import com.hanamaki.unit.junit.util.JDBCUtil;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class CalcTestNg {

    static Calc calc;

    @BeforeClass
    public void setUp() {
        calc = new Calc();
    }

    @Test
    public void test() {
        int add = calc.add(2, 3);
        System.out.println(add);
        Assert.assertEquals(add, 5);
    }

    @Test(dataProvider = "dp1")
    public void testDp1(int a, int b, int result) {
        int add = calc.add(a, b);
        System.out.println(add);
        Assert.assertEquals(add, result);
    }

    @Test(dataProvider = "dp2")
    public void testDp2(String a, String b, String result) {
        int add = calc.add(Integer.parseInt(a), Integer.parseInt(b));
        System.out.println(add);
        Assert.assertEquals(add, Integer.parseInt(result));
    }

    @Test(dataProvider = "dp3")
    public void testDp3(String a, String b, String result) {
        int add = calc.add(Integer.parseInt(a), Integer.parseInt(b));
        System.out.println(add);
        Assert.assertEquals(add, Integer.parseInt(result));
    }

    @DataProvider
    public Object[][] dp1() {
        return new Object[][]{
                new Object[]{2, 3, 5},
                new Object[]{5, 5, 10},
                new Object[]{2, 3, 4},
                new Object[]{5, 3, 8}
        };
    }

    @DataProvider
    public Object[][] dp3() {
        return FileUtil.getFileContent("src/com/hanamaki/unit/junit/calc.txt");
    }
}
